package com.sdhs.paas.itims.service;

import java.util.List;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.sdhs.paas.sdk.base.common.BaseDao;
import com.sdhs.paas.sdk.base.common.BasePage;
import com.sdhs.paas.sdk.base.page.Page;
import com.sdhs.paas.sdk.core.PaasBaseException;
import com.sdhs.paas.sdk.core.mybatis.EnablePaasMybatis;
import com.sdhs.paas.itims.bean.AppInfoBean;
import com.sdhs.paas.itims.repository.AppInfoMapper;

/**
* 描述：AppInfoService 服务接口
* @author kangjichang
* @date 2018-09-18
*/

@EnablePaasMybatis
@MapperScan("com.sdhs.paas.itims.repository")
@Service
public class AppInfoService extends BaseDao<AppInfoBean, AppInfoMapper, Integer>{
		@Override
		public String getMapperNamespace() {
			return AppInfoMapper.class.getName();
		}
		
		@Autowired
		private AppInfoMapper appInfoMapper;
		
		@SuppressWarnings("deprecation")
		public Page<AppInfoBean> getPageAppInfoList(BasePage pageRequest, AppInfoBean appInfoBean) {
			pageRequest.setFilters(appInfoBean);
			Page<AppInfoBean> page = pageQuery(pageRequest);
			return page;
		}
		
		@Transactional(rollbackFor = Exception.class)
		public boolean saveAppInfo(AppInfoBean appInfoBean) {
			try {
				//ucAppBean.setCtime(System.currentTimeMillis());
				//ucAppBean.setUtime(System.currentTimeMillis());
				int count = appInfoMapper.insertAppInfo(appInfoBean);
				return count == 1;
			} catch (Exception e) {
				throw new PaasBaseException(e, "500", "数据库插入异常！");
			}
		}
	
		@Transactional(rollbackFor = Exception.class)
		public boolean updateAppInfo(AppInfoBean appInfoBean) {
			try {
				//ucAppBean.setUtime(System.currentTimeMillis());
				int count = appInfoMapper.updateAppInfo(appInfoBean);
				return count == 1;
			} catch (Exception e) {
				throw new PaasBaseException(e, "500", "数据库插入异常！");
			}
		}
	
		public AppInfoBean getAppInfoDetail(String id) {
			return appInfoMapper.getAppInfoDetail(id);
		}
		
		public boolean deleteAppInfo(AppInfoBean appInfoBean){
			return appInfoMapper.deleteAppInfo(appInfoBean)>0;
		}
      
}